package com.tj.collection.controller.lending;

import com.fqgj.common.api.Page;
import com.fqgj.common.utils.DateUtil;
import com.fqgj.log.factory.LogFactory;
import com.fqgj.log.interfaces.Log;
import com.tj.collection.bean.ModuleResponse;
import com.tj.collection.common.RequestLocalInfo;
import com.tj.collection.controller.lending.request.ClPaidListRequest;
import com.tj.collection.controller.lending.response.ClPaidListResponse;
import com.tj.collection.db.dao.ClQueryDao;
import com.tj.collection.db.entity.business.ClPaidEntity;
import com.tj.collection.utils.ConfigUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: pavan
 * Date: 2019/9/6
 * Time: 下午2:40
 */
@RestController
@RequestMapping("/collection/v2")
public class ClPaidListController {

    public static final Log LOGGER = LogFactory.getLog(ClPaidListController.class);
    @Autowired
    private ConfigUtil configUtil;
    @Autowired
    private ClQueryDao clQueryDao;

    /**
     * 查询催后状催收人列表
     *
     * @return
     */
    @RequestMapping("/paid/list")
    public ModuleResponse<ClPaidListResponse> getCollectionPaidList(@RequestBody ClPaidListRequest clPaidListRequest, Page page) {
        String merchantCode = RequestLocalInfo.getCurrentAdmin().getMerchantCode();
        List<ClPaidEntity> clPaidEntityList = clQueryDao.selectCollectionPaidList(merchantCode,
                DateUtil.getDate(clPaidListRequest.getStartDate(), "yyyy-MM-dd"),
                DateUtil.addDate(DateUtil.getDate(clPaidListRequest.getEndDate(), "yyyy-MM-dd"), 1),
                page);
        return new ModuleResponse<>(new ClPaidListResponse(clPaidEntityList), page);
    }

    /**
     * 查询催后状催收人列表
     *
     * @return
     */
    @RequestMapping("/paid/list/export")
    public ModuleResponse<ClPaidListResponse> collectionPaidListExport(@RequestBody ClPaidListRequest clPaidListRequest, Page page) {
//        if (!configUtil.getCollectionExportAllow()) {
//            throw new ApplicationException("System exception");
//        }
        String merchantCode = RequestLocalInfo.getCurrentAdmin().getMerchantCode();
        List<ClPaidEntity> clPaidEntityList = clQueryDao.selectCollectionPaidList(merchantCode,
                DateUtil.getDate(clPaidListRequest.getStartDate(), "yyyy-MM-dd"),
                DateUtil.addDate(DateUtil.getDate(clPaidListRequest.getEndDate(), "yyyy-MM-dd"), 1),
                page);
        return new ModuleResponse<>(new ClPaidListResponse(clPaidEntityList, true), page);
    }

}
